package com.qianfeng.smartdevices.controller;


import com.qianfeng.smartdevices.annotations.AopLogAnnotation;
import com.qianfeng.smartdevices.dto.R;
import com.qianfeng.smartdevices.pojo.Menu;
import com.qianfeng.smartdevices.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/menus")
public class MenuController {

    private MenusService menusService;

    @Autowired
    public void setMenusService(MenusService menusService) {
        this.menusService = menusService;
    }

    @GetMapping("/menus")
    @AopLogAnnotation("菜单查询")
    public R findAllMenus() {
        List<Menu> menusList = menusService.findALlLeftMenus();//获取到所有的菜单
        return R.setOK(menusList);
    }
    @PostMapping("/menus")
    @AopLogAnnotation("添加菜单")
    public R addMenu(@RequestBody Menu menu){
        menusService.addMenu(menu);
        return R.setOK();
    }

    @PutMapping("/menus")
    @AopLogAnnotation("菜单更新")
    public R updateMenu(Menu menu){
        menusService.updateMenu(menu);
        return R.setOK();
    }
}
